﻿<UserControl xmlns:Views="clr-namespace:DaxStudio.UI.Views"  x:Class="DaxStudio.UI.Views.QueryResultsPaneView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ui="clr-namespace:DaxStudio.UI"
             xmlns:conv="clr-namespace:DaxStudio.UI.Converters"
             xmlns:custom="clr-namespace:DaxStudio.UI.AttachedProperties"
             mc:Ignorable="d" 
             d:DesignHeight="100" d:DesignWidth="400">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary  Source="pack://application:,,,/DaxStudio.UI;Component/Resources/IconResourceDictionary.xaml" />
                <ResourceDictionary Source="pack://application:,,,/DaxStudio.UI;Component/Resources/Styles/MetaDataPaneViewStyle.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/DaxStudio.UI;Component/Styles/BusyPanel.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/DaxStudio.UI;Component/Styles/LabelSpinnerStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <conv:DynamicGridViewConverter x:Key="DynamicGridViewConverter" />
            <conv:DynamicDataGridConverter x:Key="DynamicDataGridConverter" />
            <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
            <SolidColorBrush x:Key="SpinnerColorBrush" Color="White"></SolidColorBrush>


            <Style TargetType="FrameworkElement" x:Key="FadeInAnimation">
                <Setter Property="Visibility" Value="Collapsed"/>
                <Setter Property="Opacity" Value="0"/>
                <Style.Triggers>
                    <Trigger Property="Visibility" Value="Visible">
                        <Trigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Opacity"
                             From="0.0" To="1.0" Duration="0:0:0.2"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </Trigger.EnterActions>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
              Visibility="{Binding Converter={StaticResource BoolToVisibilityConverter }, Path=ShowResultsTable}">


            <!--
            <ListView x:Name="ResultsDataView"  
                      Visibility="{Binding Converter={StaticResource BoolToVisibilityConverter }, Path=ShowResultsTable}"
                      View="{Binding Path=ResultsDataView,  
                      Converter={StaticResource DynamicGridViewConverter},
                      Mode=OneWay,  
                      UpdateSourceTrigger=PropertyChanged }" 
                      SelectionMode="Extended"  
                      >
                <ListView.Resources>
                    <Style x:Key="HeaderContentPresenter"  TargetType="ContentPresenter">
                        <Setter Property="RecognizesAccessKey" Value="False"/>
                    </Style>
                </ListView.Resources>
                
            </ListView>
-->

            <DataGrid x:Name="ResultsDataView" 
                      Visibility="{Binding Converter={StaticResource BoolToVisibilityConverter }, Path=ShowResultsTable}"
                      ItemsSource="{Binding ResultsDataView}"
                      ClipboardCopyMode="IncludeHeader"
                      SelectionMode="Extended"       
                      SelectionUnit="Cell"
                      CanUserAddRows="False"
                      CanUserDeleteRows="False"
                      VerticalGridLinesBrush="WhiteSmoke" 
                      HorizontalGridLinesBrush="WhiteSmoke"
                      
                      AutoGenerateColumns="False" 
                      custom:DataGridExtension.Columns="{Binding Converter={StaticResource DynamicDataGridConverter }, Path=ResultsDataView}"
                      >
                <DataGrid.AlternatingRowBackground>

                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Offset="1" Color="#f2f2f2"/>
                        <GradientStop Color="#f7f7f7"/>
                    </LinearGradientBrush>
                </DataGrid.AlternatingRowBackground>
                <DataGrid.ColumnHeaderStyle>
                    <Style TargetType="{x:Type DataGridColumnHeader}">
                        <Setter Property="FontWeight"
                  Value="SemiBold" />
                    </Style>
                </DataGrid.ColumnHeaderStyle>
                <DataGrid.ContextMenu>
                    <ContextMenu>
                        <MenuItem Command="Copy" Icon="{StaticResource CopyIcon}"></MenuItem>
                    </ContextMenu>
                </DataGrid.ContextMenu>
            </DataGrid>



        </Grid>


        <!-- Results Message -->
        <Grid HorizontalAlignment="Center" VerticalAlignment="Top" 
                  Visibility="{Binding Converter={StaticResource BoolToVisibilityConverter }, Path=ShowResultsMessage}">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Grid.Row="0" Margin="0,30,0,0">
                <Image VerticalAlignment="Center"
                       Source="{Binding ResultsIcon, Converter={StaticResource OutputIcons}}"
                       Stretch="None"
                       Width="40"
                       Height="37"
                       Margin="0,0,10,0"
                       />
                <TextBlock x:Name="ResultsMessage" VerticalAlignment="Center"></TextBlock>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="1"
                        Visibility="{Binding Converter={StaticResource BoolToVisibilityConverter }, Path=ShowWorksheets}" 
                        >
                <TextBlock Text="Worksheet:" Padding="0,3,5,0"/>
                <ComboBox Name="cboOutputTo" 
                    Text="&lt;Output Sheet&gt;" 
                    MinWidth="120" MaxWidth="200" 
                    IsEditable="False" 
                    ItemsSource="{Binding Worksheets}" 
                    SelectedItem="{Binding SelectedWorksheet}"
                    
                    Template="{DynamicResource MetroComboBoxControlTemplate}" >
                </ComboBox>
            </StackPanel>
        </Grid>


        <!-- Busy overlay -->
        <Border 
                Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibilityConverter}}" Style="{StaticResource BusyPanel}" >
            <Grid>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                    <Label Style="{StaticResource LabelSpinnerStyle}" Height="30" VerticalContentAlignment="Center"  FontSize="18" FontWeight="Bold" Foreground="#D0000000">Running Query...</Label>
                </StackPanel>
            </Grid>
        </Border>
       
    </Grid>
</UserControl>
